{{ if .Site.Params.docs_search }}
<script type="text/javascript">
    // Since the Algolia is loaded asynchronously, we need to wait for it to be loaded before we can use it.
    document.addEventListener("DOMContentLoaded", function () {
        if (algoliasearchNetlify) {
            algoliasearchNetlify({
                appId: '{{ .Site.Params.docs_search_app_id }}',
                apiKey: '{{ .Site.Params.docs_search_api_key }}',
                siteId: '{{ .Site.Params.docs_search_site_id }}',
                branch: 'main',
                selector: 'div#search',
            });
        }
        // Replace the "submit" title with a more descriptive one
        var button = document.querySelector(".aa-SubmitButton")
        if (button) {
            button.setAttribute("title", "Search");
        }
    });
</script>
<div id="search"></div>
{{ end }}
